<?php
declare (strict_types = 1);

namespace app\api\controller\v1;

use app\api\controller\Base;
use app\api\model\User as UserModel;
use app\Request;

class BaseData extends Base
{
    public function userlist(Request $request)
    {
        try {

            $user = new UserModel();
            $keyword = $request->param('keyword');
            $page = $request->param('page');
            $pagesize = $request->param('pagesize');
            $list = $user->alias('u')
                         ->field('u.id,u.account,u.realname,u.email')
                         ->where('u.realname','like','%'.$keyword.'%')
                         ->where('u.id','>','1')
                         ->where('u.deleted','=','0')
                         ->order('id','desc')
                         ->paginate([
                            'list_rows'=> $pagesize,
                            'var_page' => 'page',
                            'page'=>$page
                         ]);

            if($list){
                $result = ["status"=>true,"msg"=>"获取列表成功！","data"=>$list];
            }else{
                $result = ["status"=>false,"msg"=>"获取列表失败！","data"=>$list];
            }
            return json($result);

        } catch (\Exception $e) {

            $error = ["status"=>false,"msg"=>$e->getMessage(),"code"=>$e->getCode()];
            return json($error);

        }

    }

}
